﻿Public Class Remuneraciones 
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            modificar.Enabled = True
            eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub
    Private Sub RemuneracionesBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles RemuneracionesBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.RemuneracionesBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub Remuneraciones_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.remuneracionescategoria' table. You can move, or remove it, as needed.
        Me.RemuneracionescategoriaTableAdapter.Fill(Me.DbFireAndIceDataSet.remuneracionescategoria)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.remuneraciones' table. You can move, or remove it, as needed.
        Me.RemuneracionesTableAdapter.Fill(Me.DbFireAndIceDataSet.remuneraciones)

    End Sub

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click

        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()

    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        'If IdempleadoLookUpEdit.Text.Length = 0 Then
        '    ErrorProvider1.SetError(IdempleadoLookUpEdit, "Debe ingresar un Empleado")
        '    Return
        'Else
        '    If DescripcionTextBox.Text.Length = 0 Then
        '        ErrorProvider1.SetError(DescripcionTextBox, "Debe ingresar una descripción")
        '        Return
        '    Else
        '        If DateTimePicker1.Text = "" Then
        '            ErrorProvider1.SetError(DateTimePicker1, "Debe ingresar una fecha")
        '            Return
        '        Else

        '            If IdremucatLookUpEdit.Text.Length = 0 Then
        '                ErrorProvider1.SetError(IdremucatLookUpEdit, "Debe ingresar una categoría")
        '                Return
        '            Else
        '                If MontoTextBox.Text = "" Then
        '                    ErrorProvider1.SetError(MontoTextBox, "Debe ingresar un monto")
        '                    Return
        '                End If
        '                ErrorProvider1.SetError(MontoTextBox, Nothing)
        '            End If
        '        End If
        '        ErrorProvider1.SetError(IdremucatLookUpEdit, Nothing)

        '    End If
        '    ErrorProvider1.SetError(DateTimePicker1, Nothing)
        'End If
        'ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        'ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)
        If IdempleadoLookUpEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(IdempleadoLookUpEdit, "Debe ingresar un empleado")
            Return
            End If
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)
        If DescripcionTextBox.Text = "" Then
            ErrorProvider1.SetError(DescripcionTextBox, "Debe ingresar una descripción")
            Return
        End If
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        If IdremucatLookUpEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(IdremucatLookUpEdit, "Debe ingresar una categoría")
            Return
        End If
        ErrorProvider1.SetError(IdremucatLookUpEdit, Nothing)

        If MontoTextEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(MontoTextEdit, "Debe ingresar un monto")
            Return
        End If
        ErrorProvider1.SetError(MontoTextEdit, Nothing)


            Try
                RemuneracionesBindingNavigatorSaveItem.PerformClick()

                AlertControl1.AppearanceCaption.ForeColor = Color.Green
                AlertControl1.Show(Me, "Advertencia", "Se guardó el resgistro satisfactoriamente")
                Mostrar()
            Catch ex As Exception
                AlertControl1.AppearanceCaption.ForeColor = Color.Red
                AlertControl1.Show(Me, "Error", "No se pudo guardar el registro")
            End Try

    End Sub

    Private Sub cancelar_Click(sender As System.Object, e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)
        ErrorProvider1.SetError(IdremucatLookUpEdit, Nothing)
        ErrorProvider1.SetError(DateTimePicker1, Nothing)
        ErrorProvider1.SetError(MontoTextEdit, Nothing)
        TextEdit1.Text = ""
        TextEdit2.Text = ""
        TextEdit3.Text = ""
        Mostrar()
        Try
            Me.RemuneracionesTableAdapter.Fill(Me.DbFireAndIceDataSet.remuneraciones)
        Catch
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "No se puede cancelar")
        End Try
    End Sub

    Private Sub imprimir_Click(sender As System.Object, e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub




    Private Sub IdempleadoLookUpEdit_EditValueChanged_1(sender As System.Object, e As System.EventArgs) Handles IdempleadoLookUpEdit.EditValueChanged
        If Not IsDBNull(IdempleadoLookUpEdit) Then  'si no es nulo el lookupedit
            TextEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("idcargo")
            TextEdit2.EditValue = IdempleadoLookUpEdit.GetColumnValue("apellido")
            TextEdit3.EditValue = IdempleadoLookUpEdit.GetColumnValue("nombre")
            ImageEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("fotografia")
        End If
    End Sub

    Private Sub eliminar_Click(sender As System.Object, e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                RemuneracionesTableAdapter.DeleteRemuneracionesQuery(IdcorrelativoTextBox.Text)
                Me.RemuneracionesTableAdapter.Fill(Me.DbFireAndIceDataSet.remuneraciones)
                AlertControl1.AppearanceCaption.ForeColor = Color.Green
                AlertControl1.Show(Me, "Advertencia", "Se eliminó satisfactoriamente")
            Catch ex As Exception
                AlertControl1.AppearanceCaption.ForeColor = Color.Red
                AlertControl1.Show(Me, "Error", "No se pudo eliminar el registro")
            End Try


        End If
    End Sub



    Private Sub MontoTextEdit_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles MontoTextEdit.KeyPress


        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")

            MontoTextEdit.Focus()

        Else


            If Char.IsSeparator(e.KeyChar) Then
                e.Handled = True
                AlertControl1.AppearanceCaption.ForeColor = Color.Red
                AlertControl1.Show(Me, "Advertencia", "No debe ingresar espacios")

                MontoTextEdit.Focus()

            Else
                e.Handled = False

            End If
        End If



    End Sub

    Private Sub ComisionesTextBox_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles ComisionesTextBox.KeyPress
        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")

            ComisionesTextBox.Focus()

        ElseIf Char.IsSeparator(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "No debe ingresar espacios")

            ComisionesTextBox.Focus()

        Else
            e.Handled = False

        End If
    End Sub

   

End Class